package com.yf.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootConfiguration
public class CorsConfig implements WebMvcConfigurer {
    @Value("${custom.allow-cors-domain}")
    private String[] allowCorsDomain;
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        if (allowCorsDomain == null || allowCorsDomain.length == 0) {
            return;
        }
        registry
                .addMapping("/**")
                .allowedMethods("*")
                .allowedOrigins(allowCorsDomain)
                .allowCredentials(true)
                .allowedHeaders("*");
    }
}
